from pyecharts.charts import Pie
from pyecharts import options as opts
from pyecharts.faker import Faker

# 创建饼图对象
d = (
    Pie()
    .add("", [list(t) for t in zip(Faker.choose(), Faker.values())])
    .set_colors(['red', 'green', 'blue', 'orange', 'yellow', 'white', 'black'])
    .set_global_opts(
        title_opts=opts.TitleOpts(title='饼图2，设置颜色'),
        legend_opts=opts.LegendOpts(
            type_='scroll',
            pos_left='90%',
            orient='vertical',
        )
    )
    .set_series_opts(
        label_opts=opts.LabelOpts(
            position="inside",
            formatter="{b}: {c} ({d}%)"
        )
    )
)

# 渲染图表到HTML文件，可以在浏览器中查看
d.render("pie_chart.html")